package com.googlecode.utterlyidle.multipart;

import com.googlecode.utterlyidle.Entity;

import java.io.UnsupportedEncodingException;

public class Boundary {
    private String boundary;

    public Boundary(String boundary) {
        this.boundary = boundary;
    }

    public static Boundary boundary(String boundary) {
        return new Boundary(boundary);
    }

    public static Boundary prefix(Boundary boundary) {
        return boundary("--" + boundary);
    }

    public static Boundary suffix(Boundary boundary) {
        return boundary(boundary + "--");
    }

    public Boundary prefixed() {
        return prefix(this);
    }

    public Boundary suffixed() {
        return suffix(this);
    }

    @Override
    public String toString() {
        return boundary;
    }

    public byte[] toBytes() throws UnsupportedEncodingException {
        return boundary.getBytes(Entity.DEFAULT_CHARACTER_SET);
    }
}
